package com.markerhub.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.markerhub.entity.SysMajor;
import com.markerhub.mapper.SysMajorMapper;
import com.markerhub.service.SysMajorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wang
 * @since 2022-03-31
 */
@Service
public class SysMajorServiceImpl extends ServiceImpl<SysMajorMapper, SysMajor> implements SysMajorService {

    @Override
    public List<SysMajor> listMajorsByCollegeId(Long CollegeId) {
        List<SysMajor> sysMajors = this.list(new QueryWrapper<SysMajor>().inSql("id", "select id from sys_major where college_id =" + CollegeId));
        return sysMajors;
    }

    @Override
    public Long getIdByMajor(String major) {

        return getOne(new QueryWrapper<SysMajor>().eq("major",major)).getId();
    }

    @Override
    public SysMajor getByMajorNme(String oldName) {
        return getOne(new QueryWrapper<SysMajor>().eq("major",oldName));
    }

    @Override
    public SysMajor getObject(String major) {
        return getOne(new QueryWrapper<SysMajor>().eq("major",major));
    }

    @Override
    public String getMajorNameById(Long major) {
        return getOne(new QueryWrapper<SysMajor>().eq("id",major)).getMajor();
    }


}
